﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Boo.Lang.Compiler.Ast;
using MbUnit.Framework;
using Mite.DSL;

namespace Mite.Core.Tests.Unit
{
	[TestFixture]
	public class PromoteBlockExpressionToArgumentTransformerTestFixture
	{
		[Test]
		public void BlockExpression_is_transformed_to_MacroArgument()
		{
			const string sleValue = "value1";

			ReturnStatement returnStatement = new ReturnStatement();
			returnStatement.Expression = new StringLiteralExpression(sleValue);

			Block block = new Block();
			block.Add(returnStatement);

			MacroStatement macroStatement = new MacroStatement();
			macroStatement.Name = "DoStuff";
			macroStatement.Block = block;

			PromoteBlockExpressionToArgumentTransformer transformer = new PromoteBlockExpressionToArgumentTransformer("DoStuff");
			transformer.Visit(macroStatement);

			Assert.IsFalse(macroStatement.Block.HasStatements);

			ReturnStatement rs =
				(macroStatement.Arguments[0] as BlockExpression).Body.Statements[0] as ReturnStatement;

			Assert.IsNotNull(rs, "Expected statement one of MacroStatement to be a ReturnStatement");

			StringLiteralExpression sle = rs.Expression as StringLiteralExpression;
			Assert.AreEqual(sleValue, sle.Value);
		}
	}
}
